﻿package com.element 
{
	import com.event.EventZheng;
	import com.staticInfo.EventConst;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	/**
	 * 这是一个父类,摆放在地图上物体,包括动物,植物,房屋等.
	 * @author zhengzihua
	 */
	public class Clips extends MovieClip
	{
		//物体在地图上显示的行列坐标，以及，占的行数，还有列数
		private var _sx:int;
		private var _sy:int;	
		private var _row:int;
		private var _cols:int;
		//物体放在地图上的时候，将第几行，第几列的值变为1
		private var _obstacleRow:int;
		private var _obstacleCols:int;
		
		private var _directionAng:int;//物体摆放的方位，默认为0，0，左上，1，右下，2，左下，3，右上。
		
		private var _level:int=100;//在地图上的层级,删除该元件的时候,需要用到
		private var txt:TextField;
		
		private var _listNum:String;//在objectlist中的编号
		
		public function Clips() 
		{	
			stop();
			addEventListener(MouseEvent.ROLL_OVER, onMouseOver);
			addEventListener(MouseEvent.ROLL_OUT, onMouseOut);
			addEventListener(MouseEvent.CLICK, onMouseClick);
			txt = new TextField();
			txt.selectable = false;
			txt.autoSize=TextFieldAutoSize.LEFT
			addChild(txt);
		}
		public function init(row:int,cols:int,obstacleRow:int,obstacleCols:int,listNum:String):void {
			this._row = row;
			this._cols = cols;
			this._obstacleRow = obstacleRow;
			this._obstacleCols = obstacleCols;
			this._listNum = listNum;
		}
		private function onMouseClick(e:MouseEvent):void 
		{
			var event:EventZheng = new EventZheng(EventConst.EVENT_CLIPMENU_MAIN);
			event.obj.type = "clipClick";
			event.obj.clip = this;
			parent.parent.dispatchEvent(event);
		}
		
		private function onMouseOut(e:MouseEvent):void 
		{
			var sprite:Sprite = e.currentTarget as Sprite;
			sprite.filters = null;
		}
		
		private function onMouseOver(e:MouseEvent):void 
		{
			var sprite:Sprite = e.currentTarget as Sprite;
			var color:int=0xFFFF00;
			var alpha:int=20;
			var blur_X:int=5;
			var blur_Y:int=5;
			var s:int=2;
			var q:int=2;
			var ig:Boolean=false;
			var k:Boolean=false;

			var filter:GlowFilter = new GlowFilter(color,alpha,blur_X,blur_Y,s,q,ig,k);
			var filterss:Array = new Array();
			filterss.push(filter);
			sprite.filters = filterss;
		}
		
		public function get sx():int { return _sx; }
		
		public function set sx(value:int):void 
		{
			_sx = value;
		}
		
		public function get sy():int { return _sy; }
		
		public function set sy(value:int):void 
		{
			_sy = value;
		}
		
		public function get row():int { return _row; }
		
		public function set row(value:int):void 
		{
			_row = value;
		}
		
		public function get cols():int { return _cols; }
		
		public function set cols(value:int):void 
		{
			_cols = value;
		}
		
		public function get level():int { return _level; }
		
		public function set level(value:int):void 
		{
			_level = value;
			txt.text = String(value);
		}
		
		public function get directionAng():int { return _directionAng; }
		
		public function set directionAng(value:int):void 
		{
			if (value > 3) {
				_directionAng=0
			}else{
				_directionAng = value;
			}
			gotoAndStop(_directionAng + 1);
		}
		
		public function get listNum():String { return _listNum; }
		
		public function set listNum(value:String):void 
		{
			_listNum = value;
		}
		
		public function get obstacleRow():int { return _obstacleRow; }
		
		public function set obstacleRow(value:int):void 
		{
			_obstacleRow = value;
		}
		
		public function get obstacleCols():int { return _obstacleCols; }
		
		public function set obstacleCols(value:int):void 
		{
			_obstacleCols = value;
		}
		
	}
	
}